home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
SAT 2.3.8
/
Demos
/
SAT Invaders demo ƒ
/
StarField.p
< prev
Wrap
Text File
|
1996-05-23
|
3KB
|
105 lines
{ Starfield unit for SAT Invaders.}
{This unit uses the pixel array operations in SAT.}
{Richard Bannister deserves credits for making a similar improved SAT Invaders,}
{though using sprites for the stars. His demo convinced me that there should be}
{single pixel operations in SAT. }
unit StarField;
interface
uses
{$IFC UNDEFINED THINK_PASCAL}
Types, Memory, QuickDraw,
{$ENDC}
SAT, SATAddOnLib;
{procedure InitStars;}
procedure DoStars;
procedure ToggleStarField (starFieldFlag: Boolean);
implementation
var
px, pxcopy: PixelPtr;
const
kNumPixels = 100;
procedure InitStars;
var
i: Integer;
begin
px := PixelPtr(NewPtrClear(SizeOf(Pixel) * kNumPixels));
pxcopy := PixelPtr(NewPtrClear(SizeOf(Pixel) * kNumPixels));
for i := 0 to kNumPixels - 1 do
begin
px^[i].data1 := 0; {SATRand(7) - 3}
px^[i].data2 := SATRand(7) + 1;
px^[i].position.h := SATRand(gSAT.offSizeH);
px^[i].position.v := SATRand(gSAT.offSizeV);
end;
end; {InitStars}
procedure ToggleStarField (starFieldFlag: Boolean);
var
savePort: SATPort;
begin
if starFieldFlag then
begin
SATGetPort(savePort);
SATSetPortBackScreen;
ForeColor(blackColor);
PaintRect(gSAT.backScreen.bounds);
CopyBits(gSAT.backScreen.port^.portBits, gSAT.offScreen.port^.portBits, gSAT.backScreen.bounds, gSAT.backScreen.bounds, srcCopy, nil);
SATRedraw;
SATSetPort(savePort);
end
else
begin
SATGetPort(savePort);
SATDrawPICTs(129, 128);
SATRedraw;
SATSetPort(savePort);
end;
end; {ToggleStarField}
{The pixel set is processed wit the assumption that all pixels move every frame.}
{They are drawn on top of the sprites.}
procedure DoStars;
var
i: Integer;
begin
if px = nil then
InitStars;
BlockMove(Ptr(px), Ptr(pxcopy), GetPtrSize(Ptr(px))); {Make a copy}
for i := 0 to kNumPixels - 1 do
begin
px^[i].position.h := px^[i].position.h + px^[i].data1;
px^[i].position.v := px^[i].position.v + px^[i].data2;
if px^[i].position.h < 0 then
begin
px^[i].position.h := 0;
px^[i].data1 := Abs(px^[i].data1);
end;
if px^[i].position.v < 0 then
begin
px^[i].position.v := 0;
px^[i].data2 := Abs(px^[i].data2);
end;
if px^[i].position.h >= gSAT.offSizeH then
begin
px^[i].position.h := gSAT.offSizeH - 1;
px^[i].data1 := -Abs(px^[i].data1);
end;
if px^[i].position.v >= gSAT.offSizeV then
begin
px^[i].position.v := 0;
{gSAT.offSizeV - 1;}
{px^[i].data2 := -Abs(px^[i].data2);}
end;
end;
SATDrawPixels(px, gSAT.wind, $ffffff00); {Draw in new positions}
SATCopyPixels(pxcopy, gSAT.offScreen, gSAT.wind); {Erase old positions}
end; {DoStars}
end.